package com.ysqcould.web.controller.mp;

import cn.hutool.core.util.ObjectUtil;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.enums.QrCodeStatus;
import com.ysqcould.common.utils.DateUtils;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.mp.domain.MpToken;
import com.ysqcould.mp.domain.vo.WxResultBody;
import com.ysqcould.mp.service.IMpTokenService;
import com.ysqcould.mp.utils.HttpUtils;
import com.ysqcould.mp.utils.MyCookieStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

import static com.ysqcould.allocation.utils.UploadFileUtil.AliOSSUpload;
import static com.ysqcould.mp.utils.QrCodeUtil.*;

/**
 * 登录TOKENController
 * 
 * @author ruoyi
 * @date 2022-10-18
 */
@RestController
@RequestMapping("/mp/token")
public class MpTokenController extends BaseController
{
    @Autowired
    private IMpTokenService mpTokenService;

    /**
     * 查询登录TOKEN列表
     */
    @PreAuthorize("@ss.hasPermi('mp:token:list')")
    @GetMapping("/list")
    public TableDataInfo list(MpToken mpToken)
    {
        startPage();
        List<MpToken> list = mpTokenService.selectMpTokenList(mpToken);
        return getDataTable(list);
    }


    /**
     * 获取登录二维码
     */
    @PostMapping("/getQrCode")
    public AjaxResult getQrcode(){

        final AjaxResult qrCode = mpTokenService.getQrCode();
        return qrCode;
    }

    /**
     * 导出登录TOKEN列表
     */
    @PreAuthorize("@ss.hasPermi('mp:token:export')")
    @Log(title = "登录TOKEN", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MpToken mpToken)
    {
        List<MpToken> list = mpTokenService.selectMpTokenList(mpToken);
        ExcelUtil<MpToken> util = new ExcelUtil<MpToken>(MpToken.class);
        util.exportExcel(response, list, "登录TOKEN数据");
    }

    /**
     * 获取登录TOKEN详细信息
     */
    @PreAuthorize("@ss.hasPermi('mp:token:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mpTokenService.selectMpTokenById(id));
    }

    /**
     * 新增登录TOKEN
     */
    @PreAuthorize("@ss.hasPermi('mp:token:add')")
    @Log(title = "登录TOKEN", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpToken mpToken)
    {
        return toAjax(mpTokenService.insertMpToken(mpToken));
    }

    /**
     * 修改登录TOKEN
     */
    @PreAuthorize("@ss.hasPermi('mp:token:edit')")
    @Log(title = "登录TOKEN", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpToken mpToken)
    {
        return toAjax(mpTokenService.updateMpToken(mpToken));
    }

    /**
     * 删除登录TOKEN
     */
    @PreAuthorize("@ss.hasPermi('mp:token:remove')")
    @Log(title = "登录TOKEN", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mpTokenService.deleteMpTokenByIds(ids));
    }
}
